#include <iostream>
#include <stack>
using namespace std;
class MQueue{
private:
    stack<int> inStack;
    stack<int> outStack;
    size_t size_;
public:
    MQueue():size_(0){}
    void push(int x) {
        inStack.push(x);
        ++size_;
    }
    int pop() {
        if (outStack.empty()) {
            while (!inStack.empty()) {
                outStack.push(inStack.top());
                inStack.pop();
            }
        }
        int result = outStack.top();
        outStack.pop();
        --size_;
        return result;
    }
    int peek() {
        if (outStack.empty()) {
            while (!inStack.empty()) {
                outStack.push(inStack.top());
                inStack.pop();
            }
        }
        return outStack.top();
    }
    size_t size() const {
        return size_;
    }
};
int main(){
    
    MQueue queue;
    queue.push(1);
    queue.push(2);
    queue.push(3);
    cout<<queue.peek()<<endl;
    cout<<queue.pop()<<endl;
    cout<<queue.pop()<<endl;
    cout<<queue.pop()<<endl;
    queue.push(4);
    queue.push(5);
    cout<<queue.peek()<<endl;
    cout<<queue.pop()<<endl;
    queue.push(6);
    cout<<queue.peek()<<endl;
    cout<<queue.pop()<<endl;
    cout<<queue.pop()<<endl;
    MQueue sizeQueue;
    cout<<sizeQueue.size()<<endl;
    sizeQueue.push(1);
    cout<<sizeQueue.size()<<endl;
    return 0;
}